<template>
	<div class="particle" ref="containerRef">
    <!-- 添加元旦祝福横幅 -->
    <div class="new-year-banner">
      <div class="banner-content">
        <div class="firework"></div>
        <div class="greeting-text">
          <h1>🎊 Happy New Year 2024 🎊</h1>
          <p>愿新的一年充满希望与欢乐</p>
        </div>
        <div class="firework"></div>
      </div>
    </div>

	<!-- 祝福语容器 -->
    <div class="blessings-container">
      <div v-for="(blessing, index) in blessings" 
           :key="index"
           class="blessing-card"
           :class="{ 'visible': isVisible[index] }"
           ref="blessingRefs">
        <div class="blessing-content">
          <div class="blessing-icon">{{blessing.icon}}</div>
          <h3>{{blessing.title}}</h3>
          <p>{{blessing.content}}</p>
        </div>
      </div>

      <!-- 返回首页按钮 -->
      <div class="home-button" 
           v-show="showHomeButton"
           @click="goHome">
        返回首页 🏠
      </div>
    </div>

    <!-- 添加固定的雪花背景 -->
    <div class="snowfall">
      <div v-for="n in 50" :key="n" 
           class="snowflake"
           :style="{
             '--delay': `${Math.random() * 5}s`,
             '--duration': `${Math.random() * 3 + 2}s`,
             '--position': `${Math.random() * 100}%`
           }"
      >
        ❄
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, onUnmounted } from 'vue';
import { useRouter } from 'vue-router';

const router = useRouter();
const containerRef = ref(null);
const blessingRefs = ref([]);
const isVisible = ref([]);
const showHomeButton = ref(false);

// 祝福语数据
const blessings = [
  {
    icon: '🌟',
    title: '新年快乐',
    content: '愿你在新的一年里，心想事成，万事如意！'
  },
  {
    icon: '✨',
    title: '健康平安',
    content: '愿你和家人在新的一年里身体健康，平安喜乐！'
  },
  {
    icon: '💫',
    title: '事业有成',
    content: '愿你在新的一年里事业蒸蒸日上，前程似锦！'
  },
  {
    icon: '🌈',
    title: '幸福美满',
    content: '愿你在新的一年里幸福美满，快乐常在！'
  },
  {
    icon: '💝',
    title: '心想事成',
    content: '愿你在新的一年里所有愿望都能实现！'
  }
];

// 初始化可见性数组
isVisible.value = new Array(blessings.length).fill(false);

// 检查元素是否在视口中
const checkVisibility = () => {
  blessingRefs.value.forEach((el, index) => {
    if (!el) return;
    
    const rect = el.getBoundingClientRect();
    const isInViewport = rect.top <= window.innerHeight * 0.8;
    
    if (isInViewport && !isVisible.value[index]) {
      isVisible.value[index] = true;
      
      // 如果是最后一个祝福语显示了，显示返回按钮
      if (index === blessings.length - 1) {
        setTimeout(() => {
          showHomeButton.value = true;
        }, 1000);
      }
    }
  });
};

// 返回首页
const goHome = () => {
	router.push('/');
};

onMounted(() => {
  window.addEventListener('scroll', checkVisibility);
  // 初始检查
  checkVisibility();
});

onUnmounted(() => {
  window.removeEventListener('scroll', checkVisibility);
});
</script>

<style lang="scss">

.particle {
  min-height: 100vh;
  background: linear-gradient(135deg, #000428, #004e92);
  position: relative;
  overflow: hidden;
  animation: gradientShift 15s ease infinite;

  // 添加星星背景
  &::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    background-image: 
      radial-gradient(white 1px, transparent 1px),
      radial-gradient(white 1px, transparent 1px);
    background-size: 50px 50px;
    background-position: 0 0, 25px 25px;
    opacity: 0.1;
    animation: twinkle 3s ease-in-out infinite;
  }

  .new-year-banner {
    position: relative;
    width: 100%;
    background: linear-gradient(135deg, rgba(255, 77, 77, 0.95), rgba(246, 65, 108, 0.95));
    padding: 20px 0;
    box-shadow: 
      0 5px 25px rgba(0, 0, 0, 0.2),
      0 0 5px rgba(255, 255, 255, 0.1);
    transform-origin: top;
    animation: bannerDrop 1s cubic-bezier(0.34, 1.56, 0.64, 1);

    .banner-content {
      display: flex;
      justify-content: center;
      align-items: center;
      gap: 30px;
      padding: 0 20px;

      .firework {
        position: relative;
        width: 30px;
        height: 30px;

        &::before, &::after {
          content: '✨';
          position: absolute;
          font-size: 28px;
          animation: sparkle 2s ease-in-out infinite;
        }

        &::after {
          animation-delay: 1s;
        }
      }

      .greeting-text {
        text-align: center;
        color: white;
        
        h1 {
          font-size: 28px;
          font-weight: 700;
          margin: 0;
          text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
          animation: glow 2s ease-in-out infinite;
          letter-spacing: 1px;
        }

        p {
          font-size: 16px;
          margin: 8px 0 0;
          opacity: 0.9;
          font-weight: 500;
          letter-spacing: 0.5px;
          animation: slideIn 0.8s ease-out forwards;
        }
      }
    }
  }
}

// 动画关键帧
@keyframes gradientShift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

@keyframes bannerDrop {
  from {
    opacity: 0;
    transform: translateY(-100%) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes sparkle {
  0%, 100% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
  50% {
    transform: scale(1.2) rotate(180deg);
    opacity: 0.8;
  }
}

@keyframes glow {
  0%, 100% {
    text-shadow: 
      0 0 10px rgba(255, 255, 255, 0.8),
      0 0 20px rgba(255, 255, 255, 0.5),
      0 0 30px rgba(255, 255, 255, 0.3);
  }
  50% {
    text-shadow: 
      0 0 15px rgba(255, 255, 255, 0.9),
      0 0 25px rgba(255, 255, 255, 0.6),
      0 0 35px rgba(255, 255, 255, 0.4);
  }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes twinkle {
  0%, 100% {
    opacity: 0.1;
  }
  50% {
    opacity: 0.2;
  }
}

// 雪花容器
.snowfall {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

// 雪花样式
.snowflake {
  position: fixed;
  top: -20px;
  color: white;
  font-size: 20px;
  text-shadow: 
    0 0 5px rgba(255, 255, 255, 0.8),
    0 0 10px rgba(255, 255, 255, 0.4);
  opacity: 0.8;
  pointer-events: none;
  animation: snowfall var(--duration) linear infinite;
  animation-delay: var(--delay);
  left: var(--position);
  
  &:nth-child(even) {
    font-size: 16px;
  }
  
  &:nth-child(3n) {
    font-size: 14px;
  }
}

// 雪花飘落动画
@keyframes snowfall {
  0% {
    transform: translateY(-20px) rotate(0deg);
    opacity: 0;
  }
  20% {
    opacity: 0.8;
  }
  80% {
    opacity: 0.8;
  }
  100% {
    transform: translateY(100vh) rotate(360deg);
    opacity: 0;
  }
}

// 优化背景样式
.particle {
  min-height: 100vh;
  background: linear-gradient(135deg, #000428, #004e92);
  position: relative;
  overflow: hidden;
  animation: gradientShift 15s ease infinite;

  // 添加星星背景
  &::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    background-image: 
      radial-gradient(white 1px, transparent 1px),
      radial-gradient(white 1px, transparent 1px);
    background-size: 50px 50px;
    background-position: 0 0, 25px 25px;
    opacity: 0.1;
    animation: twinkle 3s ease-in-out infinite;
  }

  // 添加北极光效果
  &::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 60vh;
    background: linear-gradient(
      180deg,
      transparent,
      rgba(32, 147, 255, 0.1) 20%,
      rgba(32, 147, 255, 0) 100%
    );
    filter: blur(20px);
    animation: auroraFlow 8s ease-in-out infinite alternate;
  }
}
.blessings-container {
  padding: 100px 20px;
  max-width: 800px;
  margin: 0 auto;
  
  .blessing-card {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 30px;
    margin: 40px 0;
    opacity: 0;
    transform: translateY(50px);
    transition: all 0.8s cubic-bezier(0.4, 0, 0.2, 1);
    
    &.visible {
      opacity: 1;
      transform: translateY(0);
    }
    
    .blessing-content {
      text-align: center;
      color: white;
      
      .blessing-icon {
        font-size: 48px;
        margin-bottom: 20px;
        animation: float 3s ease-in-out infinite;
      }
      
      h3 {
        font-size: 24px;
        margin-bottom: 15px;
        background: linear-gradient(45deg, #fff, #f0f0f0);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
      }
      
      p {
        font-size: 16px;
        line-height: 1.6;
        opacity: 0.9;
      }
    }
  }
}

.home-button {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: white;
  padding: 15px 30px;
  border-radius: 30px;
  font-size: 18px;
  cursor: pointer;
  opacity: 0;
  animation: fadeInUp 0.8s ease forwards;
  box-shadow: 
    0 10px 20px rgba(0, 0, 0, 0.2),
    0 0 0 1px rgba(255, 255, 255, 0.1);
  transition: all 0.3s ease;
  
  &:hover {
    transform: translateX(-50%) translateY(-3px);
    box-shadow: 0 15px 25px rgba(0, 0, 0, 0.3);
  }
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translate(-50%, 20px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}
</style>